Function Import-ScheduledTask(){
    [CmdletBinding()]param(
		[string]$vdi=$env:COMPUTERNAME,
		[string]$folder = "\",
		[string]$task_name,
		[ValidateScript({test-path $_})]
		[string]$xml,
		[string]$domain="nam",
		[string]$fid="aaadmin",
		[string]$pswd,
		[string]$sid,  # (New-Object System.Security.Principal.NTAccount($ad_user)).Translate([System.Security.Principal.SecurityIdentifier]).value
		[boolean]$refresh,
		[switch]$RunOnlyLogon,
		[switch]$RunWithLowAccess
	)
	$arg = ([xml](cat "$xml")).Task.Actions.Exec.Arguments
	Try{
	    $stf = Get-TaskFolder $vdi $domain $fid $pswd $folder $refresh
		Try{
			$st = $stf.ImportTask($task_name,$xml)
		}Catch{
			Write-Warning "found 1.0 scheduled task, try to use old method to create task"
			SCHTASKS /CREATE /S $vdi /RU System /NP /RL HIGHEST /tn $task_name /sc ONCE /st (get-date).tostring("HH:mm") /F /tr ("powershell.exe {0}" -f $arg) 1>$null 2>&1 
			$st = (Get-TaskFolder $vdi $domain $fid $pswd $folder).GetTasks($task_name)
		}Finally{}
		
		If( $RunOnlyLogon){
		    $st.Definition.Principal.LogonType = "InteractiveToken"
			$st.Definition.Principal.UserId = $sid
			if($RunWithLowAccess){
				$st.Definition.Principal.RunLevel='LUA'
			}
			$st.RegisterChanges()
		}
		return $st
	}Catch{
	    throw $_
	}Finally{}
}